package pl.donajski.magisterka;

import java.util.List;
import java.util.Random;

public class SubstitutionGenerator implements IMoveGenerator {
	
	public SubstitutionGenerator(State s, float penaltyRatio) {
		this.mTasks = s.getTasks();
		this.mNodes = s.getNodes();
		for(Node n : mNodes) {
			mSumOfProcessingRateMax += n.getProcessingRateMax();
		}
		this.mPenaltyRatio = penaltyRatio;
	}
	
	public IMove getRandomMove() {
		Random r = new Random();
		int t = 0,
			n = 0;
		
		do {
			while((t = Math.abs(r.nextInt())) < 0);
			while((n = Math.abs(r.nextInt())) < 0);
			t = t%mTasks.size();
			n = n%mNodes.size();
		} while(mTasks.get(t).getAssignment().getIndex() == n);
		
		return new Substitution(mTasks.get(t), 
				mNodes.get(n), mPenaltyRatio, mSumOfProcessingRateMax);
	}
	
	public IMove getMove(Task t, Node n) {
		return new Substitution(t, n, mPenaltyRatio, mSumOfProcessingRateMax);
	}
	
	private List<Task> mTasks;
	private List<Node> mNodes;;
	private int mSumOfProcessingRateMax = 0;
	private float mPenaltyRatio;

}
